/*!
 RowReorder 1.1.0
 2015 SpryMedia Ltd - datatables.net/license
*/
(function(e){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(f){return e(f,window,document)}):"object"===typeof exports?module.exports=function(f,g){f||(f=window);if(!g||!g.fn.dataTable)g=require("datatables.net")(f,g).$;return e(g,f,f.document)}:e(jQuery,window,document)})(function(e,f,g){var h=e.fn.dataTable,i=function(b,a){if(!h.versionCheck||!h.versionCheck("1.10.8"))throw"DataTables RowReorder requires DataTables 1.10.8 or newer";this.c=e.extend(!0,{},h.defaults.rowReorder,
i.defaults,a);this.s={bodyTop:null,dt:new h.Api(b),getDataFn:h.ext.oApi._fnGetObjectDataFn(this.c.dataSrc),middles:null,setDataFn:h.ext.oApi._fnSetObjectDataFn(this.c.dataSrc),start:{top:0,left:0,offsetTop:0,offsetLeft:0,nodes:[]},windowHeight:0};this.dom={clone:null};var d=this.s.dt.settings()[0],c=d.rowreorder;if(c)return c;d.rowreorder=this;this._constructor()};e.extend(i.prototype,{_constructor:function(){var b=this,a=this.s.dt,d=e(a.table().node());"static"===d.css("position")&&d.css("position",
"relative");e(a.table().container()).on("mousedown.rowReorder touchstart.rowReorder",this.c.selector,function(c){var d=e(this).closest("tr");if(a.row(d).any())return b._mouseDown(c,d),!1});a.on("destroy.rowReorder",function(){e(a.table().container()).off(".rowReorder");a.off(".rowReorder")})},_cachePositions:function(){var b=this.s.dt,a=e(b.table().node()).find("thead").outerHeight(),d=e.unique(b.rows({page:"current"}).nodes().toArray()),c=e.map(d,function(b){return e(b).position().top-a}),d=e.map(c,
function(a,d){return c.length<d-1?(a+c[d+1])/2:(a+a+e(b.row(":last-child").node()).outerHeight())/2});this.s.middles=d;this.s.bodyTop=e(b.table().body()).offset().top;this.s.windowHeight=e(f).height()},_clone:function(b){var a=e(this.s.dt.table().node().cloneNode(!1)).addClass("dt-rowReorder-float").append("<tbody/>").append(b.clone(!1)),d=b.outerWidth(),c=b.outerHeight(),g=b.children().map(function(){return e(this).width()});a.width(d).height(c).find("tr").children().each(function(a){this.style.width=
g[a]+"px"});a.appendTo("body");this.dom.clone=a},_clonePosition:function(b){var a=this.s.start,d=this._eventToPage(b,"Y")-a.top,b=this._eventToPage(b,"X")-a.left,c=this.c.snapX;this.dom.clone.css({top:d+a.offsetTop,left:!0===c?a.offsetLeft:"number"===typeof c?a.offsetLeft+c:b+a.offsetLeft})},_emitEvent:function(b,a){this.s.dt.iterator("table",function(d){e(d.nTable).triggerHandler(b+".dt",a)})},_eventToPage:function(b,a){return-1!==b.type.indexOf("touch")?b.originalEvent.touches[0]["page"+a]:b["page"+
a]},_mouseDown:function(b,a){var d=this,c=this.s.dt,k=this.s.start,j=a.offset();k.top=this._eventToPage(b,"Y");k.left=this._eventToPage(b,"X");k.offsetTop=j.top;k.offsetLeft=j.left;k.nodes=e.unique(c.rows({page:"current"}).nodes().toArray());this._cachePositions();this._clone(a);this._clonePosition(b);this.dom.target=a;a.addClass("dt-rowReorder-moving");e(g).on("mouseup.rowReorder touchend.rowReorder",function(a){d._mouseUp(a)}).on("mousemove.rowReorder touchmove.rowReorder",function(a){d._mouseMove(a)});
e(f).width()===e(g).width()&&e(g.body).addClass("dt-rowReorder-noOverflow")},_mouseMove:function(b){this._clonePosition(b);for(var a=this._eventToPage(b,"Y")-this.s.bodyTop,d=this.s.middles,c=null,k=this.s.dt,j=k.table().body(),f=0,i=d.length;f<i;f++)if(a<d[f]){c=f;break}null===c&&(c=d.length);if(null===this.s.lastInsert||this.s.lastInsert!==c)0===c?this.dom.target.prependTo(j):(a=e.unique(k.rows({page:"current"}).nodes().toArray()),c>this.s.lastInsert?this.dom.target.before(a[c-1]):this.dom.target.after(a[c])),
this._cachePositions(),this.s.lastInsert=c;b=this._eventToPage(b,"Y")-g.body.scrollTop;c=this.s.scrollInterval;65>b?c||(this.s.scrollInterval=setInterval(function(){g.body.scrollTop=g.body.scrollTop-5},15)):65>this.s.windowHeight-b?c||(this.s.scrollInterval=setInterval(function(){g.body.scrollTop=g.body.scrollTop+5},15)):(clearInterval(c),this.s.scrollInterval=null)},_mouseUp:function(){var b=this.s.dt,a,d,c=this.c.dataSrc;this.dom.clone.remove();this.dom.clone=null;this.dom.target.removeClass("dt-rowReorder-moving");
e(g).off(".rowReorder");e(g.body).removeClass("dt-rowReorder-noOverflow");clearInterval(this.s.scrollInterval);this.s.scrollInterval=null;var f=this.s.start.nodes,j=e.unique(b.rows({page:"current"}).nodes().toArray()),i={},h=[],l=[],m=this.s.getDataFn,p=this.s.setDataFn;a=0;for(d=f.length;a<d;a++)if(f[a]!==j[a]){var n=b.row(j[a]).id(),q=b.row(j[a]).data(),o=b.row(f[a]).data();n&&(i[n]=m(o));h.push({node:j[a],oldData:m(q),newData:m(o),newPosition:a,oldPosition:e.inArray(j[a],f)});l.push(j[a])}this._emitEvent("row-reorder",
[h,{dataSrc:c,nodes:l,values:i,triggerRow:b.row(this.dom.target)}]);this.c.editor&&this.c.editor.edit(l,!1,{submit:"changed"}).multiSet(c,i).submit();if(this.c.update){a=0;for(d=h.length;a<d;a++)f=b.row(h[a].node).data(),p(f,h[a].newData),b.columns().every(function(){this.dataSrc()===c&&b.cell(h[a].node,this.index()).invalidate("data")});b.draw(!1)}}});i.defaults={dataSrc:0,editor:null,selector:"td:first-child",snapX:!1,update:!0};i.version="1.1.0";e.fn.dataTable.RowReorder=i;e.fn.DataTable.RowReorder=
i;e(g).on("init.dt.dtr",function(b,a){if("dt"===b.namespace){var d=a.oInit.rowReorder,c=h.defaults.rowReorder;if(d||c)c=e.extend({},d,c),!1!==d&&new i(a,c)}});return i});
